﻿using System;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Web.WebPages.Html;
using System.Configuration;
using Recaptcha;
using System.Web.UI;
using System.IO;

namespace MvcApplication2.Models
{
    public class User
    {
        public int UserID { get; set; }
        [Required(ErrorMessage = "Musisz podać login")]
        [Display(Name = "Login")]
        public string Login { get; set; }
        [Required(ErrorMessage = "Musisz podać hasło")]
        [Display(Name = "Hasło")]
        public string Password { get; set; }
        [Display(Name = "Imię")]
        public string FirstName { get; set; }
        [Display(Name = "Nazwisko")]
        public string LastName { get; set; }
        [Display(Name = "E-mail")]
        public string Email { get; set; }
        [Display(Name = "Wiek")]
        public int? Age { get; set; }
        [Display(Name = "Miejscowość")]
        public string City { get; set; }
        [Display(Name = "Admin")]
        public bool Admin { get; set; }
        [Display(Name = "Zablokowany")]
        public bool Blocked { get; set; }

        public virtual ICollection<Vote> Votes { get; set; }
        public virtual ICollection<Recipe> Recipes { get; set; }
        public virtual ICollection<CookBook> CookBooks { get; set; }
    }

    public class Vote
    {
        public int ID { get; set; }
        public int UserID { get; set; }
        public int RecipeID { get; set; }
        [Display(Name = "Ocena")]
        public bool Like { get; set; }

        public virtual User User { get; set; }
        public virtual Recipe Recipe { get; set; }
    }

    public class Recipe
    {
        public int RecipeID { get; set; }
        public int? UserID { get; set; }
        public int? CategoryID { get; set; }
        [Display(Name = "Obrazek")]
        public string ImagePath { get; set; }
        [Required(ErrorMessage = "Musisz podać tytuł przepisu")]
        [Display(Name = "Tytuł")]
        public string Title { get; set; }
        [Required(ErrorMessage = "Musisz podać opis przepisu")]
        [Display(Name = "Opis")]
        public string Description { get; set; }

        public virtual ICollection<Vote> Votes { get; set; }
        public virtual ICollection<CookBookRecipe> CookBookRecipes { get; set; }
        public virtual User User { get; set; }
        public virtual Category Category { get; set; }
    }

    public class Category
    {
        public int CategoryID { get; set; }
        //public int CategoryID { get; set; }
        [Display(Name = "Nazwa")]
        public string Name { get; set; }
        [Display(Name = "Opis")]
        public string Description { get; set; }

        public virtual ICollection<Recipe> Recipes { get; set; }
        //public virtual Category Category { get; set; }
    }

    public class CookBook
    {
        public int CookBookID { get; set; }
        public int? UserID { get; set; }
        [Display(Name = "Nazwa")]
        public string Name { get; set; }
        [Display(Name = "Opis")]
        public string Description { get; set; }

        public virtual User User { get; set; }
        public virtual ICollection<CookBookRecipe> CookBookRecipes { get; set; }
    }

    public class CookBookRecipe
    {
        public int ID { get; set; }
        //[Column(Order = 0)]
        //[Key]
        public int RecipeID { get; set; }
        //[Column(Order = 1)]
        //[Key]
        public int CookBookID { get; set; }

        public virtual Recipe Recipe { get; set; }
        public virtual CookBook CookBook { get; set; }
    }

    public class Movie {
        public int ID { get; set; }

        [Required(ErrorMessage = "Title is required")]
        public string Title { get; set; }

        [Required(ErrorMessage = "Date is required")]
        [DisplayFormat(DataFormatString = "{0:d}")]
        public DateTime ReleaseDate { get; set; }

        [Required(ErrorMessage = "Genre must be specified")]
        public string Genre { get; set; }

        [Required(ErrorMessage = "Price Required")]
        [Range(1, 100, ErrorMessage = "Price must be between $1 and $100")]
        [DisplayFormat(DataFormatString = "{0:c}")]
        public decimal Price { get; set; }

        [StringLength(5)]
        public string Rating { get; set; }
    }

    public class BaseDBContext : DbContext
    {
        public DbSet<Movie> Movies { get; set; }
        public DbSet<Vote> Votes { get; set; }
        public DbSet<Recipe> Recipes { get; set; }
        public DbSet<User> Users { get; set; }
        public DbSet<CookBook> CookBooks { get; set; }
        public DbSet<CookBookRecipe> CookBookRecipes { get; set; }
        public DbSet<Category> Categories { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }

    }

}

